package com.byxy.demo01.service.impl;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.byxy.demo01.dao.ForumDao;
import com.byxy.demo01.dao.TabDao;
import com.byxy.demo01.dao.TipDao;
import com.byxy.demo01.dao.UserDao;
import com.byxy.demo01.entity.Forum;
import com.byxy.demo01.entity.Tab;
import com.byxy.demo01.entity.Tip;
import com.byxy.demo01.entity.User;
import com.byxy.demo01.service.TipSrevice;
import com.byxy.demo01.vo.TipVo;

@Service
@Transactional
public class TipServiceImpl implements TipSrevice{
	@Autowired
	private TipDao tipDao;
	@Autowired
	private UserDao userDao;
	@Autowired
	private TabDao tabDao;
	@Autowired
	private ForumDao forumDao;
	@Override
	public void add(Tip tip) {
		// TODO Auto-generated method stub
		tipDao.add(tip);
	}
	@Override
	public TipVo findById(Integer tipId) {
		Tip tip = tipDao.findBid(tipId);
		TipVo tipVO = new TipVo();
		BeanUtils.copyProperties(tip, tipVO);
		User u = userDao.getById(tip.getUserId());
		
		if (u.getUserNick()!= null && u.getUserNick().equals("")) 
			tipVO.setUserName(u.getUserNick());
		else {
			tipVO.setUserName(u.getUserName());
			}
			Tab tab = tabDao.getById(tip.getTabId());
			tipVO.setTabName(tab.getTabName());
			Forum forum =forumDao.getById(tab.getForumId());
			tipVO.setForumName(forum.getForumName());
		return tipVO;
	}
	
	
}
